export const useMenuStore = defineStore('menu', () => {
  const menus = ref<any[]>([])

  const formatMenus = (routes: any[]) => {
    routes = JSON.parse(JSON.stringify(routes)) || []
    const handler = (routes: any[], path?: string) => {
      routes.forEach((route: any) => {
        route.component = null
        if (!path || path === '/') {
          route.path = path + route.path
        } else {
          route.path = path + '/' + route.path
        }

        route.children = handler(route.children || [], route.path)
      })
      return routes.filter(item => item.meta?.showMenu !== false)
    }

    menus.value = handler(routes, '')
  }

  return { menus, formatMenus }
})
